﻿using System;
using System.Web;
using Facebook;
using Sketchial.UIProcess;

namespace Skecthial.UI.Controls
{
    public partial class ProfileBox : BoxUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie cookie = Request.Cookies["TokenCookie"]; /// it returns a null even if the cookie exisits
            if (cookie != null)
            {
                string TOKEN = cookie.Values["TOKEN"].ToString();
                var accessToken = TOKEN;
                if (Context.Session["AccessToken"] != null)
                    accessToken = Context.Session["AccessToken"].ToString();
                var client = new FacebookClient(accessToken);
                dynamic result = client.Get("me", new { fields = "name,id" });
                string name = result.name;
                string id = result.id;

                literalProfileName.Text = name;
            }
            else
            {
                Response.Redirect("~/pages/login.aspx", false);
            }
        }
    }
}